import axios from 'axios'

export const CHANGE_INPUT_VALUE = 'CHANGE_INPUT_VALUE'
export const ADD_ITEM = 'ADD_ITEM'
export const DELETE_TODO_ITEM = 'DELETE_TODO_ITEM'
export const INI_LIST = 'INI_LIST'
export const GET_INIT_LIST = 'GET_INIT_LIST'

export const getInputValueAction = (value) => ({
  type: CHANGE_INPUT_VALUE,
  value
})

export const getDeleteItemAction = (index) => ({
  type: DELETE_TODO_ITEM,
  index
})

export const getAddItemAction = () => ({
  type: ADD_ITEM
})

export const getIniListAction = (list) => ({
  type: INI_LIST,
  list
})

export const getInitListThunk = () => {
  return (dispatch) => {
    axios.get('/list.json').then( res =>{
      const data = res.data
      dispatch(getIniListAction(data))
    })
  }
}
